$(function(){
	
	//商品数量加减

	var stockNum = parseInt($('.info-num').attr('stock_num'));

	$('.info-num').append('<span></span>');

	$("#info-num").blur(function(){
		var inNum = parseInt($("#info-num").val());
		statistical_num(inNum,stockNum);
	});

	$('.info-num .pre').click(function(){
		var inNum = parseInt($("#info-num").val())-1;
		statistical_num(inNum,stockNum);
	});
	$('.info-num .next').click(function(){
		var inNum = parseInt($("#info-num").val())+1;
		statistical_num(inNum,stockNum);
	});

	function statistical_num(inNum,stockNum){

		if((/^(\+|-)?\d+$/.test( inNum ))&&inNum>0){ 
			if(inNum > stockNum){
				$("#info-num").val(stockNum);
				$('.info-num span').hide();
			}else{
				$("#info-num").val(inNum);
				$('.info-num span').hide();
			}
		}else{
			// $('.info-num span').show().html('数量中请输入正整数！');
			$("#info-num").val(1);
		}	

	}

	//选择规格

	$('.product_prop .spec a').click(function(){
		var product_id = $('#product_id').val();
		var s_id = $(this).attr('s_id');
		$(this).addClass('a_on').siblings().removeClass('a_on');
		$.ajax({
            url: "/ypt_shop_details_js",
            type: "POST",
            data: 'product_id=' + product_id,
            success: function (msg) {
                if (msg) {
					$.each(msg,function(index,arr){
						if(s_id == arr.s_id){
							//console.log(arr.price);
							$('#price').html("￥"+arr.price+"");
						}
					});
                };
            }
        });
	});

	//配送地区

	$('.choose .area').hover(function(){
		$('.dv_area').show();
	},function(){
		$('.dv_area').hide();
	});

	$('.area_content li').click(function(){
		$('.choose .area span').html($(this).html());
		$('.dv_area').hide();
	});

});	